package com.ys.peony.presenter;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;

import com.ys.peony.R;
import com.ys.peony.base.BaseContract;
import com.ys.peony.base.BasePresenter;
import com.ys.peony.base.contract.CarPledgeContract;
import com.ys.peony.car300.AddBaoDanActivity;
import com.ys.peony.car300.BaoDanActivity;
import com.ys.peony.car300.BaoDanFragment;
import com.ys.peony.car300.CarDataManager;
import com.ys.peony.car300.CarInfo2Activity;
import com.ys.peony.car300.CarUpdateActivity;
import com.ys.peony.car300.ItemModel;
import com.ys.peony.car300.PledgeFragment;
import com.ys.peony.model.CarPledgeModel;
import com.ys.peony.model.domain.BaoDanAddInfo;
import com.ys.peony.model.domain.CarAddInfo;
import com.ys.peony.model.domain.CarDetailModel;
import com.ys.peony.model.domain.CarModel;
import com.ys.peony.model.domain.CityModel;
import com.ys.peony.model.domain.SaveCarModel;
import com.ys.peony.ui.activity.CarInfoActivity;
import com.ys.peony.ui.activity.CarPledgeActivity;
import com.ys.peony.utils.JSONUtil;
import com.ys.peony.utils.SharePreferencesUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 59153 on 2017/7/31.
 */

public class CarPledgePresenter extends BasePresenter<CarPledgeModel, BaseContract.IBaseView> implements CarPledgeContract.iCarPledgePresenter {

    private String PARAM_USERID = "userId";
    private String PARAM_LOANID = "loanId";
    private String PARAM_ID = "id";//车辆唯一标识 取vehicle_code,添加的时候为空
    private String PARAM_BRAND_NAME = "brand_name";//车辆品牌名称
    private String PARAM_BRAND_ID = "brand_id";//车辆品牌主键
    private String PARAM_SERIES_ID_DESR = "series_id_desr";
    private String PARAM_SERIES_ID = "series_id"; //车系id
    private String PARAM_MODEL_ID = "model_id"; //车型id
    private String PARAM_MODEL_ID_DESR = "model_id_desr"; //和vehicle_type传一样的数据

    private String PARAM_COLOR = "color";//车辆颜色
    private String PARAM_INTERIOR = "interior";//内饰状况
    private String PARAM_SURFACE = "surface";//外观
    private String PARAM_WORK_STATE = "work_state";//工况状况
    private String PARAM_TRANSFER_TIMES = "transfer_times";//过户次数
    private String PARAM_PROV_ID = "prov_id";//省id
    private String PARAM_CITY_ID = "city_id";//城市id
    private String PARAM_PROV_ID_DESR = "prov_id_desr";//省描述
    private String PARAM_CITY_ID_DESR = "city_id_desr";//城市描述
    private String PARAM_KILOMETER = "kilometer"; //公里数
    private String PARAM_VEHICLE_ID = "vehicle_id";//车辆vin码
    private String PARAM_VEHICLE_TYPE = "vehicle_type";//车辆型号
    private String PARAM_ENGINE_NUMBER = "engine_number";//发动机号
    private String PARAM_ATTRIBUTION_AREA = "attribution_area";//车牌地区
    private String PARAM_PLATE_NUMBER = "plate_number";//车牌号
    private String PARAM_PRICE = "price"; //购买价格
    private String PARAM_TIME_BUYING = "time_buying"; //购买时间
    private String PARAM_TIME_AWARDED = "time_awarded"; //发证时间

    private String PARAM_OWNERSHIP_TAG = "ownership_tag";//权属类型
    private String PARAM_OWNERSHIP_PERSON = "ownership_person"; //权属人
    private String PARAM_SOURCE_TYPE = "source_type";//来源类型 默认1
    private String PARAM_MAKE_DATE = "make_date";//出厂日期
    private String PARAM = "vehicleList[0].";
    private String PARAM_BAODAN = "busivehicleguaranteeslip.";

    private String VEHICLE_PARAMS = "vehicle_params";

    private Handler mHandler = new Handler(Looper.getMainLooper());

    public CarPledgePresenter() {
        relateModel(new CarPledgeModel(this));
    }

    @Override
    public void getPledgeUserList() {

    }

    @Override
    public void getCarByVin(String vin) {
        model.getCarByVin(vin);
    }


    @Override
    public void getCarInfoById(String loanId) {
        String userId = SharePreferencesUtils.getInstance().getUserId();
        model.getCarInfoById(Long.valueOf(loanId), Long.valueOf(userId));
    }

    @Override
    public boolean isValidInput(String input) {
        if (input.length() == 17) {
            return true;
        }
        return false;
    }


    @Override
    public List<ItemModel> getItemModel(List list, int viewId) {
        List<ItemModel> itemModels = new ArrayList<>();
        switch (viewId) {
            case R.id.car_color:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarcolorListBean vehicleCarcolorListBean = (CarDetailModel.VehicleCarcolorListBean) list.get(i);
                    String text = vehicleCarcolorListBean.getText();
                    if (!TextUtils.isEmpty(text)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setText(text);
                        itemModel.setVal(String.valueOf(vehicleCarcolorListBean.getVal()));
                        itemModels.add(itemModel);
                    }
                }
                break;

            case R.id.car_qs:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleOwnershopTagListBean vehicleOwnershopTagListBean = (CarDetailModel.VehicleOwnershopTagListBean) list.get(i);
                    String text = vehicleOwnershopTagListBean.getText();
                    String val = vehicleOwnershopTagListBean.getVal();
                    if (!TextUtils.isEmpty(text) && !TextUtils.isEmpty(val)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setVal(val);
                        itemModel.setText(text);
                        itemModels.add(itemModel);
                    }
                }
                break;
            case R.id.car_gongkuang:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarworkstateListBean vehicleCarworkstateListBean = (CarDetailModel.VehicleCarworkstateListBean) list.get(i);
                    String text = vehicleCarworkstateListBean.getText();
                    if (!TextUtils.isEmpty(text)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setText(text);
                        itemModel.setVal(String.valueOf(vehicleCarworkstateListBean.getVal()));
                        itemModels.add(itemModel);
                    }
                }
                break;
            case R.id.car_area: {
                CarDetailModel.AreaListBean areaListBeen = ((List<CarDetailModel.AreaListBean>) list).get(0);
                if (areaListBeen == null) {
                    return null;
                }
                List<CarDetailModel.AreaListBean.SysAreaListBeanXX> sysAreaListBeanXXes = areaListBeen.getSysAreaList();
                int t = -1;
                for (int i = 0; i < sysAreaListBeanXXes.size(); i++) {

                    if ("浙江省".equals(sysAreaListBeanXXes.get(i).getName())) {
                        t = i;
                        break;
                    }

                }
                if (t != -1) {
                    List<CarDetailModel.AreaListBean.SysAreaListBeanXX.SysAreaListBeanX> sysAreaListBeanX = sysAreaListBeanXXes.get(t).getSysAreaList();
                    for (int j = 0; j < sysAreaListBeanX.size(); j++) {
                        if (!TextUtils.isEmpty(sysAreaListBeanX.get(j).getBrand())) {
                            ItemModel itemModel = new ItemModel();
                            itemModel.setText(sysAreaListBeanX.get(j).getBrand());
                            itemModel.setVal(String.valueOf(sysAreaListBeanX.get(j).getId()));
                            itemModels.add(itemModel);
                        }
                    }
                }
                break;
            }
            case R.id.car_decorate:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarinteriorListBean vehicleCarinteriorListBean = (CarDetailModel.VehicleCarinteriorListBean) list.get(i);
                    String text = vehicleCarinteriorListBean.getText();
                    if (!TextUtils.isEmpty(text)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setText(text);
                        itemModel.setVal(String.valueOf(vehicleCarinteriorListBean.getVal()));
                        itemModels.add(itemModel);
                    }
                }
                break;
            case R.id.car_apperance:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarsurfaceListBean vehicleCarsurfaceListBean = (CarDetailModel.VehicleCarsurfaceListBean) list.get(i);
                    String text = vehicleCarsurfaceListBean.getText();
                    if (!TextUtils.isEmpty(text)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setText(text);
                        itemModel.setVal(String.valueOf(vehicleCarsurfaceListBean.getVal()));
                        itemModels.add(itemModel);
                    }
                }
                break;
            case R.id.tax_company:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.GuaranteeSlipInsuranceCompanyListBean guaranteeSlipInsuranceCompanyListBean = ((CarDetailModel.GuaranteeSlipInsuranceCompanyListBean) list.get(i));
                    String text = guaranteeSlipInsuranceCompanyListBean.getText();
                    String val = guaranteeSlipInsuranceCompanyListBean.getVal();
                    if (!TextUtils.isEmpty(text) && !TextUtils.isEmpty(val)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setVal(val);
                        itemModel.setText(text);
                        itemModels.add(itemModel);
                    }
                }
                break;
            case R.id.tax_type:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.GuaranteeSlipGuaranteeSlipTypeListBean guaranteeSlipGuaranteeSlipTypeListBeen = ((List<CarDetailModel.GuaranteeSlipGuaranteeSlipTypeListBean>) list).get(i);
                    String text = guaranteeSlipGuaranteeSlipTypeListBeen.getText();
                    String val = guaranteeSlipGuaranteeSlipTypeListBeen.getVal();
                    if (!TextUtils.isEmpty(text) && !TextUtils.isEmpty(val)) {
                        ItemModel itemModel = new ItemModel();
                        itemModel.setVal(val);
                        itemModel.setText(text);
                        itemModels.add(itemModel);
                    }
                }
                break;
        }
        return itemModels;
    }

    @Override
    public String getItemTextById(List list, int viewId, String id) {
        switch (viewId) {
            case R.id.car_color:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarcolorListBean vehicleCarcolorListBean = (CarDetailModel.VehicleCarcolorListBean) list.get(i);
                    String val = vehicleCarcolorListBean.getVal();
                    if (id.equals(val)) {
                        return vehicleCarcolorListBean.getText();
                    }
                }
                break;
            case R.id.car_gongkuang:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarworkstateListBean vehicleCarworkstateListBean = (CarDetailModel.VehicleCarworkstateListBean) list.get(i);
                    String val = vehicleCarworkstateListBean.getVal();
                    if (id.equals(val)) {
                        return vehicleCarworkstateListBean.getText();
                    }
                }
                break;
            case R.id.car_decorate:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarinteriorListBean vehicleCarinteriorListBean = (CarDetailModel.VehicleCarinteriorListBean) list.get(i);
                    String val = vehicleCarinteriorListBean.getVal();
                    if (id.equals(val)) {
                        return vehicleCarinteriorListBean.getText();
                    }
                }
                break;
            case R.id.car_apperance:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleCarsurfaceListBean vehicleCarsurfaceListBean = (CarDetailModel.VehicleCarsurfaceListBean) list.get(i);
                    String val = vehicleCarsurfaceListBean.getVal();
                    if (id.equals(val)) {
                        return vehicleCarsurfaceListBean.getText();
                    }
                }
                break;
            case R.id.car_area:
                CarDetailModel.AreaListBean areaListBeen = ((List<CarDetailModel.AreaListBean>) list).get(0);
                if (areaListBeen == null) {
                    return null;
                }
                List<CarDetailModel.AreaListBean.SysAreaListBeanXX> sysAreaListBeanXXes = areaListBeen.getSysAreaList();
                int t = -1;
                for (int i = 0; i < sysAreaListBeanXXes.size(); i++) {

                    if ("浙江省".equals(sysAreaListBeanXXes.get(i).getName())) {
                        t = i;
                        break;
                    }

                }
                if (t != -1) {
                    List<CarDetailModel.AreaListBean.SysAreaListBeanXX.SysAreaListBeanX> sysAreaListBeanX = sysAreaListBeanXXes.get(t).getSysAreaList();
                    for (int j = 0; j < sysAreaListBeanX.size(); j++) {
                        String val = String.valueOf(sysAreaListBeanX.get(j).getId());
                        if (id.equals(val)) {
                            return sysAreaListBeanX.get(j).getBrand();
                        }
                    }
                }
                break;
            case R.id.tax_type_tv:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.GuaranteeSlipGuaranteeSlipTypeListBean guaranteeSlipGuaranteeSlipTypeListBean = (CarDetailModel.GuaranteeSlipGuaranteeSlipTypeListBean) list.get(i);
                    String val = guaranteeSlipGuaranteeSlipTypeListBean.getVal();
                    if (id.equals(val)) {
                        return guaranteeSlipGuaranteeSlipTypeListBean.getText();
                    }
                }
                break;
            case R.id.car_qs:
                for (int i = 0; i < list.size(); i++) {
                    CarDetailModel.VehicleOwnershopTagListBean vehicleOwnershopTagListBean = (CarDetailModel.VehicleOwnershopTagListBean) list.get(i);
                    String val = vehicleOwnershopTagListBean.getVal();
                    if (id.equals(val)) {
                        return vehicleOwnershopTagListBean.getText();
                    }
                }
                break;

        }
        return "";
    }

    /**
     * 获取城市信息
     */
    @Override
    public void getCity() {
        model.getCity();
    }

    @Override
    public void addPledgeCar() {
        Map<String, Object> params = new HashMap<>();
        CarAddInfo carAddInfo = CarDataManager.getInstance().getmCarAddInfo();
        if (carAddInfo != null) {
            params.put(PARAM_USERID, CarDataManager.getInstance().getUserId());
            params.put(PARAM_LOANID, CarDataManager.getInstance().getLoanId());
            params.put(PARAM + PARAM_ID, carAddInfo.getId());
            params.put(PARAM + PARAM_BRAND_NAME, carAddInfo.getBrand_name());
            params.put(PARAM + PARAM_BRAND_ID, carAddInfo.getBrand_id());
            params.put(PARAM + PARAM_SERIES_ID_DESR, carAddInfo.getSeries_id_desr());
            params.put(PARAM + PARAM_COLOR, carAddInfo.getColor());
            params.put(PARAM + PARAM_INTERIOR, carAddInfo.getInterior());
            params.put(PARAM + PARAM_SURFACE, carAddInfo.getSurface());
            params.put(PARAM + PARAM_SERIES_ID, carAddInfo.getSeries_id());
            params.put(PARAM + PARAM_MODEL_ID, carAddInfo.getModel_id());
            params.put(PARAM + PARAM_MODEL_ID_DESR, carAddInfo.getModel_id_desr());
            params.put(PARAM + PARAM_WORK_STATE, carAddInfo.getWork_state());
            params.put(PARAM + PARAM_TRANSFER_TIMES, carAddInfo.getTransfer_times());
            params.put(PARAM + PARAM_PROV_ID, carAddInfo.getProv_id());
            params.put(PARAM + PARAM_CITY_ID, carAddInfo.getCity_id());
            params.put(PARAM + PARAM_PROV_ID_DESR, carAddInfo.getProv_id_desr());
            params.put(PARAM + PARAM_CITY_ID_DESR, carAddInfo.getCity_id_desr());
            params.put(PARAM + PARAM_KILOMETER, carAddInfo.getKilometer());
            params.put(PARAM + PARAM_VEHICLE_ID, carAddInfo.getVehicle_id());
            params.put(PARAM + PARAM_VEHICLE_TYPE, carAddInfo.getVehicle_type());
            params.put(PARAM + PARAM_ENGINE_NUMBER, carAddInfo.getEngine_number());
            params.put(PARAM + PARAM_ATTRIBUTION_AREA, carAddInfo.getAttribution_area());
            params.put(PARAM + PARAM_PLATE_NUMBER, carAddInfo.getPlate_number());
            params.put(PARAM + PARAM_PRICE, carAddInfo.getPrice());
            params.put(PARAM + PARAM_TIME_BUYING, carAddInfo.getTime_buying());
            params.put(PARAM + PARAM_OWNERSHIP_TAG, carAddInfo.getOwnership_tag());
            params.put(PARAM + PARAM_OWNERSHIP_PERSON, carAddInfo.getOwnership_person());
            params.put(PARAM + PARAM_OWNERSHIP_PERSON, carAddInfo.getOwnership_person());
            params.put(PARAM + PARAM_TIME_AWARDED, carAddInfo.getTime_awarded());
            params.put(PARAM + PARAM_MAKE_DATE, carAddInfo.getMake_date());
            params.put("mortgageList[0].id", "");
            if(carAddInfo.getCarTypeParam() == null) {
                params.put(VEHICLE_PARAMS, "");
            } else {
                params.put(VEHICLE_PARAMS, JSONUtil.toJSON(carAddInfo.getCarTypeParam()));
            }
            model.addPledgeCar(params);
        }
    }

    @Override
    public void updatePledgeCar() {
        Map<String, Object> params = new HashMap<>();
        CarAddInfo carAddInfo = CarDataManager.getInstance().getmCarAddInfo();
        if (carAddInfo != null) {
            params.put(PARAM_USERID, SharePreferencesUtils.getInstance().getUserId());
            params.put(PARAM_LOANID, CarDataManager.getInstance().getLoanId());
            params.put(PARAM + PARAM_ID, carAddInfo.getId());
            params.put(PARAM + PARAM_BRAND_NAME, carAddInfo.getBrand_name());
            params.put(PARAM + PARAM_BRAND_ID, carAddInfo.getBrand_id());
            params.put(PARAM + PARAM_SERIES_ID_DESR, carAddInfo.getSeries_id_desr());
            params.put(PARAM + PARAM_COLOR, carAddInfo.getColor());
            params.put(PARAM + PARAM_INTERIOR, carAddInfo.getInterior());
            params.put(PARAM + PARAM_SURFACE, carAddInfo.getSurface());
            params.put(PARAM + PARAM_SERIES_ID, carAddInfo.getSeries_id());
            params.put(PARAM + PARAM_MODEL_ID, carAddInfo.getModel_id());
            params.put(PARAM + PARAM_MODEL_ID_DESR, carAddInfo.getModel_id_desr());
            params.put(PARAM + PARAM_WORK_STATE, carAddInfo.getWork_state());
            params.put(PARAM + PARAM_TRANSFER_TIMES, carAddInfo.getTransfer_times());
            params.put(PARAM + PARAM_PROV_ID, carAddInfo.getProv_id());
            params.put(PARAM + PARAM_CITY_ID, carAddInfo.getCity_id());
            params.put(PARAM + PARAM_PROV_ID_DESR, carAddInfo.getProv_id_desr());
            params.put(PARAM + PARAM_CITY_ID_DESR, carAddInfo.getCity_id_desr());
            params.put(PARAM + PARAM_KILOMETER, carAddInfo.getKilometer());
            params.put(PARAM + PARAM_VEHICLE_ID, carAddInfo.getVehicle_id());
            params.put(PARAM + PARAM_VEHICLE_TYPE, carAddInfo.getVehicle_type());
            params.put(PARAM + PARAM_ENGINE_NUMBER, carAddInfo.getEngine_number());
            params.put(PARAM + PARAM_ATTRIBUTION_AREA, carAddInfo.getAttribution_area());
            params.put(PARAM + PARAM_PLATE_NUMBER, carAddInfo.getPlate_number());
            params.put(PARAM + PARAM_PRICE, carAddInfo.getPrice());
            params.put(PARAM + PARAM_TIME_BUYING, carAddInfo.getTime_buying());
            params.put(PARAM + PARAM_OWNERSHIP_TAG, carAddInfo.getOwnership_tag());
            params.put(PARAM + PARAM_OWNERSHIP_PERSON, carAddInfo.getOwnership_person());
            params.put(PARAM + PARAM_OWNERSHIP_PERSON, carAddInfo.getOwnership_person());
            params.put(PARAM + PARAM_TIME_AWARDED, carAddInfo.getTime_awarded());
            params.put(PARAM + PARAM_MAKE_DATE, carAddInfo.getMake_date());
            if(carAddInfo.getCarTypeParam() == null) {
                params.put(VEHICLE_PARAMS, "");
            } else {
                params.put(VEHICLE_PARAMS, JSONUtil.toJSON(carAddInfo.getCarTypeParam()));
            }
            model.updatePledgeCar(params);
        }
    }

    @Override
    public void deletePledgeCar(String mortgageId) {
        Map<String, Object> params = new HashMap<>();
        params.put("busiLoanId", CarDataManager.getInstance().getLoanId());
        params.put("mortgageId", mortgageId);
        model.deleteCar(params);
    }

    @Override
    public void onSuccess(final Object data) {
        if (data instanceof CarModel) {
            CarDataManager.getInstance().setCarVinModel((CarModel) data);
            if (view instanceof CarInfoActivity) {
                ((CarInfoActivity) view).onResult(data);
            } else if (view instanceof PledgeFragment) {
                ((PledgeFragment) view).onSuccess(CarPledgeContract.GET_CAR_VIN);
            }
        } else if (data instanceof CarDetailModel) {
            CarDataManager.getInstance().setCarDetailModel((CarDetailModel) data);
            if (view instanceof CarInfoActivity) {
                ((CarInfoActivity) view).onResult(data);
            } else if (view instanceof BaoDanActivity) {
                ((BaoDanActivity) view).onSuccess(CarPledgeContract.GET_CAR_DETAIL);
            } else if (view instanceof PledgeFragment) {
                ((PledgeFragment) view).onSuccess(CarPledgeContract.GET_CAR_DETAIL);
            } else if (view instanceof AddBaoDanActivity) {
                ((AddBaoDanActivity) view).onSuccess(CarPledgeContract.GET_CAR_DETAIL);
            } else if (view instanceof BaoDanFragment) {
                ((BaoDanFragment) view).onSuccess(CarPledgeContract.GET_CAR_DETAIL);
            } else if(view instanceof CarPledgeActivity) {
                ((CarPledgeActivity) view).onSuccess(CarPledgeContract.GET_CAR_DETAIL);
            }

        } else if (data instanceof CityModel) {
            CarDataManager.getInstance().setmCityModel((CityModel) data);
            if(view instanceof CarInfo2Activity) {
                ((CarInfo2Activity) view).onResult(CarInfo2Activity.CODE_GET_CITY);
            } else if(view instanceof PledgeFragment) {
                ((PledgeFragment) view).onSuccess(CarPledgeContract.CODE_GET_CITY);
            }
        } else if (data instanceof SaveCarModel) {
            SaveCarModel saveCarModel = (SaveCarModel) data;
            CarDataManager.getInstance().setSaveCarModel(saveCarModel);
            if (view instanceof CarInfo2Activity) {
                ((CarInfo2Activity) view).onResult(CarInfo2Activity.CODE_SAVE_CAR);
            } else if (view instanceof PledgeFragment) {
                ((PledgeFragment) view).onSuccess(CarPledgeContract.SAVE_CAR_INFO);
            }
        } else if (data instanceof Integer) {
            if (CarPledgeContract.ADD_CAR_BAODAN == (int) data) {
                ((AddBaoDanActivity) view).onSuccess(CarPledgeContract.ADD_CAR_BAODAN);
            } else if (CarPledgeContract.DELETE_CAR_BAODAN == (int) data) {
                if (view instanceof BaoDanFragment) {
                    ((BaoDanFragment) view).onSuccess(CarPledgeContract.DELETE_CAR_BAODAN);
                }
            } else if (CarPledgeContract.DELETE_CAR == (int) data) {
                ((CarUpdateActivity) view).onSuccess(CarPledgeContract.DELETE_CAR);
            }
        }
    }

    @Override
    public void onFail(String msg) {
        view.onFail(msg);
    }

    @Override
    public void addBaoDanInfo(String vehicle_id, String baodanId) {
        Map<String, Object> params = new HashMap<>();
        BaoDanAddInfo baoDanAddInfo = CarDataManager.getInstance().getmBaoDanAddInfo();
        if (baoDanAddInfo != null) {
            /**
             * 必填
             */
            params.put(PARAM_BAODAN + "id", baodanId);
            params.put(PARAM_BAODAN + "vehicle_id", vehicle_id);
            params.put(PARAM_USERID, CarDataManager.getInstance().getUserId());
            params.put(PARAM_LOANID, CarDataManager.getInstance().getLoanId());
            params.put(PARAM_BAODAN + "guarantee_fee", baoDanAddInfo.getGuarantee_fee());
            params.put(PARAM_BAODAN + "guarantee_begin", baoDanAddInfo.getGuarantee_begin());
            params.put(PARAM_BAODAN + "guarantee_end", baoDanAddInfo.getGuarantee_end());
            params.put(PARAM_BAODAN + "signing_time", baoDanAddInfo.getSigning_time());
            params.put(PARAM_BAODAN + "guarantee_slip_type", baoDanAddInfo.getGuarantee_slip_type());
            params.put(PARAM_BAODAN + "insurance_company", baoDanAddInfo.getInsurance_company());
            params.put(PARAM_BAODAN + "insurance_company_desr", baoDanAddInfo.getInsurance_company_desr());

            /**
             * 选填
             */
            params.put(PARAM_BAODAN + "serial_number", baoDanAddInfo.getSerial_number());
            params.put(PARAM_BAODAN + "guarantee_slip_code", baoDanAddInfo.getGuarantee_slip_code());
            params.put(PARAM_BAODAN + "guarantee_slip_number", baoDanAddInfo.getGuarantee_slip_number());
            params.put(PARAM_BAODAN + "policy_holder", baoDanAddInfo.getPolicy_holder());
            params.put(PARAM_BAODAN + "insurant", baoDanAddInfo.getInsurant());
            params.put(PARAM_BAODAN + "insurant_id_card", baoDanAddInfo.getInsurant_id_card());
            params.put(PARAM_BAODAN + "address", baoDanAddInfo.getAddress());
            params.put(PARAM_BAODAN + "phone", baoDanAddInfo.getPhone());
            params.put(PARAM_BAODAN + "floating_ratio", baoDanAddInfo.getFloating_ratio());
            params.put(PARAM_BAODAN + "tax_this_year", baoDanAddInfo.getTax_this_year());
            params.put(PARAM_BAODAN + "tax_previous_year", baoDanAddInfo.getTax_previous_year());
            params.put(PARAM_BAODAN + "tax_late_fee", baoDanAddInfo.getTax_late_fee());
            params.put(PARAM_BAODAN + "tax_total", baoDanAddInfo.getTax_total());
            params.put(PARAM_BAODAN + "tax_proof", baoDanAddInfo.getTax_proof());
            params.put(PARAM_BAODAN + "proof_office", baoDanAddInfo.getProof_office());

            model.addBaoDanInfo(params);
        }
    }

    @Override
    public void deleteBaoDan(String baodan_id) {
        Map<String, Object> params = new HashMap<>();
        params.put(PARAM_USERID, SharePreferencesUtils.getInstance().getUserId());
        params.put("busiLoanId", CarDataManager.getInstance().getLoanId());
        params.put("id", baodan_id);
        model.deleteBaoDan(params);
    }
}
